package com.wondersgroup.esclient.service;


import io.netty.util.internal.StringUtil;

public class BaseESService {
	
	/**
	 * ES集群名称
	 */
	@SuppressWarnings("unused")
	private String CLUSTER_NAME;
	
	/**
	 * ES集群节点
	 */
	private String CLUSTER_NODE;
	
	/**
	 * ES index
	 */
	private String _index;
	
	/**
	 * ES type
	 */
	private String _type;

	
	public BaseESService() {

	}

	public BaseESService(String cLUSTER_NAME, String cLUSTER_NODE) {
		super();
		CLUSTER_NAME = cLUSTER_NAME;
		CLUSTER_NODE = cLUSTER_NODE;
	}

	public BaseESService(String cLUSTER_NAME, String cLUSTER_NODE, String _index, String _type) {
		super();
		CLUSTER_NAME = cLUSTER_NAME;
		CLUSTER_NODE = cLUSTER_NODE;
		this._index = _index;
		this._type = _type;
	}
	
	public String getclusterNode() {
		return this.CLUSTER_NODE;
	}
	
	/**
	 * 获取ES Host
	 * @param hasType  是否包含 type
	 * @return
	 */
	public String getESHost(boolean hasType) {
		StringBuffer host = new StringBuffer();
		host.append(this.CLUSTER_NODE);
		host.append("/" + this._index);
		if(!StringUtil.isNullOrEmpty(this._type) && hasType) {
			host.append("/" + this._type);
		}
		return host.toString();
	}

	
	public String getESHost(String index, String type) {
		StringBuffer host = new StringBuffer();
		host.append(this.CLUSTER_NODE);
		host.append("/" + index);
		if(!StringUtil.isNullOrEmpty(type)) {
			host.append("/" + type);
		}
		return host.toString();
	}
}
